# 导包
import time
from appium import webdriver
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.by import By



# 配置移动端设备信息
des_caps = {
    "platformName": "Android",  # 移动端系统平台
    "platformVersion": "12",  # 平台对应版本
    "deviceName": "mumu",  # 设备名称（可以随便写）
    "appPackage": "com.tpshop.malls",  # 包名
    "appActivity": ".SplashActivity"  # Activity页面名
}
# 初始化设备配置信息
option = UiAutomator2Options().load_capabilities(des_caps)
# 创建驱动对象
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=option)
# 暂停3秒
time.sleep(3)
for i in range(3):
    driver.swipe(900, 1000, 100, 1000, 0)
time.sleep(5)
driver.find_element(By.XPATH, "//*[@text='分类']").click()
driver.tap([(269, 240), (362, 279)], 1000)
driver.tap([(27, 214), (516, 703)], 1000)
driver.find_element(By.XPATH, "//*[@text='立即购买']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='确定']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='请输入账号']").send_keys("18683060002")
driver.find_element(By.XPATH, "//*[@text='请输入密码']").send_keys("abc123")
driver.find_element(By.ID, "com.tpshop.malls:id/agree_btn").click()
driver.find_element(By.ID, "com.tpshop.malls:id/login_tv").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='确定']").click()
time.sleep(1)
driver.find_element(By.ID, "com.tpshop.malls:id/order_address_tv").click()
driver.find_element(By.ID, "com.tpshop.malls:id/add_address_tv").click()
time.sleep(1)
driver.find_element(By.ID, "com.tpshop.malls:id/consignee_name_et").send_keys("张三")
driver.find_element(By.ID, "com.tpshop.malls:id/consignee_mobile_et").send_keys("18683060002")
driver.tap([(193, 290), (1021, 369)], 1000)
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='北京市']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='市辖区']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='东城区']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='东华门街道']").click()
driver.find_element(By.XPATH, "//*[@text='确定']").click()
driver.find_element(By.ID, "com.tpshop.malls:id/consignee_address_et").send_keys("aaa")
driver.find_element(By.ID, "com.tpshop.malls:id/set_default_sth").click()
driver.find_element(By.XPATH, "//*[@text='保存收货地址']").click()
time.sleep(1)
driver.find_element(By.ID, "com.tpshop.malls:id/address_detail_tv").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='提交订单']").click()
time.sleep(1)
driver.find_element(By.XPATH, "//*[@text='立即支付']").click()
time .sleep(1)
driver.find_element(By.XPATH, "//*[@text='确定']").click()




# 关闭驱动
time.sleep(3)
driver.quit()
